package com.fjrcloud.service;

import com.fjrcloud.dao.StorefrontStandardDao;
import com.fjrcloud.entity.StorefrontStandard;
import com.fjrcloud.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * Created by shengjian.lin on 17-1-18.
 */
@Service
public class StorefrontStandardService {

    @Autowired
    private StorefrontStandardDao dao;

    public StorefrontStandard save(StorefrontStandard store){

        store.setCreateTime(System.currentTimeMillis());

        return dao.save(store);
    }
    public StorefrontStandard get(Integer id){
        return dao.findOne(id);
    }
    public void del(Integer id){
        dao.delete(id);
    }

    public Page<StorefrontStandard> list(Integer pageNum, Integer pageSize){

        pageNum = PageUtils.checkPageNum(pageNum);
        pageSize = PageUtils.checkPageSize(pageSize);
        PageRequest pageRequest = new PageRequest(pageNum, pageSize);

        return dao.findByValidOrderByCreateTimeAsc(true,pageRequest);
    }
}
